//
//  NEDConsoleLookinViewController.m
//  NEDBugConsole_Example
//
//  Created by 98du on 2021/12/15.
//  Copyright © 2021 林宁宁. All rights reserved.
//

#import "NEDConsoleLookinViewController.h"
#import "NEDConsoleMenuItem.h"
#import "NEDConsole.h"

@interface NEDConsoleLookinViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) UITableView  *tableView;
@property(nonatomic,strong) NSArray <NEDConsoleMenuItem *>*dataSource;


@end

@implementation NEDConsoleLookinViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"Lookin 查看视图层级";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 55;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.tableHeaderView = [UIView new];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.autoresizingMask = 0xff;
    [self.view addSubview:self.tableView];
    
    
    NSMutableArray * dataList = [NSMutableArray new];
    
    NEDConsoleMenuItem * item = [NEDConsoleMenuItem new];
    item.title = @"导出为 Lookin 文档";
    item.info = @"Lookin_Export";
    [dataList addObject:item];
    
    item = [NEDConsoleMenuItem new];
    item.title = @"进入 2D 模式";
    item.info = @"Lookin_2D";
    [dataList addObject:item];
    
    item = [NEDConsoleMenuItem new];
    item.title = @"进入 3D 模式";
    item.info = @"Lookin_3D";
    [dataList addObject:item];
    
    self.dataSource = dataList;
    [self.tableView reloadData];
}

- (void)closeAction{
    [self dismissViewControllerAnimated:YES completion:nil];
}


#pragma mark - UITableView Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.text = self.dataSource[indexPath.row].title;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:self.dataSource[indexPath.row].info object:nil];
    
    [NEDConsole hiddenConsoleMenu];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
